import { useAPIUtils } from "./APIUtilsProvider";

export default function RenderIf({ auth, children }) {
  const { tanstackQuery } = useAPIUtils();
  let query = tanstackQuery(`/api/me`);

  if (!query.data) {
    return <></>;
  }

  let userRestAuthorities = query.data.userRestAuthorities;

  if (userRestAuthorities.includes(auth)) {
    return children;
  } else {
    return <></>;
  }
}
